<script setup>
import { ref } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { ElButton } from 'element-plus'
import CommonHeader from '@/components/CommonHeader.vue'
import CommonFooter from '@/components/CommonFooter.vue'
import FloatingSidebar from '@/components/FloatingSidebar.vue'

const router = useRouter()
const route = useRoute()

// 模拟订单数据
const orderInfo = ref({
  orderNo: route.query.orderNo,
  paymentAmount: route.query.paymentAmount ? Number(route.query.paymentAmount) : 0,
  paymentMethod: route.query.paymentMethod,
  paymentTime: route.query.paymentTime,
  estimatedDelivery: route.query.estimatedDelivery
})

// 继续购物
const continueShopping = () => {
  router.push('/home')
}

// 查看订单
const viewOrder = () => {
  router.push('/home/user')
}
</script>

<template>
  <CommonHeader />
  <FloatingSidebar />
  <div class="order-success-page">
    <div class="container">
      <div class="success-content">
        <div class="success-icon">
          <i class="el-icon-success"></i>
        </div>
        <h1 class="success-title">支付成功</h1>
        <p class="success-message">您的订单已支付成功，感谢您的购买！</p>

        <div class="order-info">
          <div class="info-item">
            <span class="label">订单编号：</span>
            <span class="value">{{ orderInfo.orderNo }}</span>
          </div>
          <div class="info-item">
            <span class="label">支付金额：</span>
            <span class="value price">¥{{ orderInfo.paymentAmount.toFixed(2) }}</span>
          </div>
          <div class="info-item">
            <span class="label">支付方式：</span>
            <span class="value">{{ orderInfo.paymentMethod }}</span>
          </div>
          <div class="info-item">
            <span class="label">支付时间：</span>
            <span class="value">{{ orderInfo.paymentTime }}</span>
          </div>
          <div class="info-item">
            <span class="label">预计送达：</span>
            <span class="value">{{ orderInfo.estimatedDelivery }}</span>
          </div>
        </div>

        <div class="action-buttons">
          <el-button @click="continueShopping">继续购物</el-button>
          <el-button type="primary" @click="viewOrder">查看订单</el-button>
        </div>
      </div>
    </div>
  </div>
  <CommonFooter />
</template>

<style scoped>
.order-success-page {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: calc(100vh - 120px);
}

.container {
  max-width: 800px;
  margin: 0 auto;
  background-color: #fff;
  padding: 40px;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.success-content {
  text-align: center;
}

.success-icon {
  font-size: 72px;
  color: #67c23a;
  margin-bottom: 20px;
}

.success-title {
  font-size: 28px;
  color: #303133;
  margin-bottom: 16px;
}

.success-message {
  font-size: 16px;
  color: #606266;
  margin-bottom: 40px;
}

.order-info {
  background-color: #f8f9fa;
  padding: 24px;
  border-radius: 8px;
  margin-bottom: 40px;
  text-align: left;
}

.info-item {
  display: flex;
  margin-bottom: 16px;
  line-height: 1.5;
}

.info-item:last-child {
  margin-bottom: 0;
}

.label {
  width: 100px;
  color: #909399;
}

.value {
  flex: 1;
  color: #303133;
}

.value.price {
  color: #f56c6c;
  font-weight: bold;
}

.action-buttons {
  display: flex;
  justify-content: center;
  gap: 20px;
}

/* 响应式调整 */
@media screen and (max-width: 768px) {
  .container {
    padding: 20px;
  }

  .success-icon {
    font-size: 48px;
  }

  .success-title {
    font-size: 24px;
  }

  .action-buttons {
    flex-direction: column;
  }

  .action-buttons .el-button {
    width: 100%;
  }
}
</style> 